
package mapDemo;

import java.util.HashMap;
import java.util.Map;

public class Demo3 {
	public static void main(String[] args) {
		String str = "我要努力学习，我要好好赚钱";
		Map<Character, Integer> map = count(str);
		System.out.println(map);
	}
	
	public static Map<Character, Integer> count(String s){
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		for(int i=0;i<s.length();i++){
			char c = s.charAt(i);
			if(map.containsKey(c)){
				int num = map.get(c)+1;
				//两个key值一样，覆盖value值
				map.put(c, num);
			}else{
				map.put(c, 1);
			}
		}
		
		return map;
	}
	
	
}
